function xDesktopPanelMenu() {
 p_menu = new Array();
 p_menuAttr = new Array();
 p_index = 0;
 p_subitems = false;
 p_menuAttr[1] = new Array();
 p_menuAttr[1]["top"] = 0;
 p_menuAttr[1]["left"] = 0;
 p_menuAttr[1]["height"] = 20;
 p_menuAttr[1]["width"] = 192;
 p_menuAttr[1]["offset"] = 5; // offset from left
 p_menuAttr[1]["border"] = "1px solid #000000";
 p_menuAttr[1]["class"] = "xP_mLevel1";
 p_menuAttr[1]["menu_sub"] = xDT.resPath() + "images/menu_sub.gif";
 p_menuAttr[1]["menu_sub_open"] = xDT.resPath() + "images/menu_sub_open.gif";
 p_menuAttr[1]["menu_sub_item"] = xDT.resPath() + "images/menu_sub_item.gif";
  
 p_menuAttr[2] = new Array();
 p_menuAttr[2]["height"] = 20;
 p_menuAttr[2]["offset"] = 20; // offset from left
 p_menuAttr[2]["border"] = "";
 p_menuAttr[2]["class"] = "xP_mLevel2";

 p_menuAttr[3] = new Array();
 p_menuAttr[3]["height"] = 20;
 p_menuAttr[3]["offset"] = 30; // offset from left
 p_menuAttr[3]["border"] = "";
 p_menuAttr[3]["class"] = "xP_mLevel3";

 p_menuAttr[4] = new Array();
 p_menuAttr[4]["height"] = 20;
 p_menuAttr[4]["offset"] = 40; // offset from left
 p_menuAttr[4]["border"] = "";
 p_menuAttr[4]["class"] = "xP_mLevel4";

 p_menuAttr[5] = new Array();
 p_menuAttr[5]["height"] = 20;
 p_menuAttr[5]["offset"] = 50; // offset from left
 p_menuAttr[5]["border"] = "";
 p_menuAttr[5]["class"] = "xP_mLevel5";
 
 this.addMenuItem = _addMenuItem;
 this.buildMenu = _buildMenu;
 this.showMenu = _showMenu;
 this.menuAttribute = _menuAttribute;
 this.processUrl = _processUrl;
 
 function _addMenuItem(mLevel,mName,mTitle,mTarget,mUrl) {
  if (mLevel < 1 || mLevel > 5) {alert('Error menu Level: ' + mLevel); mLevel = 1; mName = "error"; mTitle = 'ERROR mLevel' }
  if (! mName || ! mName.length) {alert('Error menu Name: ' + mName); mName = "error"; mTitle = 'ERROR mName' }
  if (! mTitle || ! mTitle.length) {alert('Error menu Title: ' + mTitle); mName = "error"; mTitle = 'ERROR mTitle' }
  if (typeof(mTarget) == 'undefined') mTarget = "";
  if (typeof(mUrl) == 'undefined') mUrl = "";  
  var mIndex = p_index;
  p_menu[mIndex] = new Array();
  p_menu[mIndex]["mIndex"] = mIndex;
  p_menu[mIndex]["mID"] = "";
  p_menu[mIndex]["mVisible"] = false;
  p_menu[mIndex]["mLevel"] = mLevel;
  p_menu[mIndex]["mSubLevel"] = false;
  p_menu[mIndex]["mName"] = mName;
  p_menu[mIndex]["mTitle"] = mTitle;
  p_menu[mIndex]["mTarget"] = mTarget;
  p_menu[mIndex]["mUrl"] = mUrl;    
  p_index++;
 }
 function _getName(mName) {
  for (var i=0;i<p_index;i++) {
   if (p_menu[i]["mName"] == mName) return true;
  }
  return false;
 }
 function _buildMenu() {
  preloadImages(p_menuAttr[1]["menu_sub"],p_menuAttr[1]["menu_sub_open"],p_menuAttr[1]["menu_sub_item"]);
  for (var i=0;i<p_index;i++) {
   if (p_menu[i]["mLevel"] != 1) {
    p_menuAttr[p_menu[i]["mLevel"]]["left"] = p_menuAttr[1]["left"];
    p_menuAttr[p_menu[i]["mLevel"]]["width"] = p_menuAttr[1]["width"];
   }
   document.write('<div id="' + p_menu[i]["mName"] + i 
                              + '" style="position: absolute; top: 0px; left: 0px; visibility: hidden; '
                              + 'width: ' + _menuAttribute(p_menu[i]["mLevel"],'width') + '; ' 
                              + 'height: ' + _menuAttribute(p_menu[i]["mLevel"],'height') + '; ' 
                              + 'border: ' + _menuAttribute(p_menu[i]["mLevel"],'border') + '; ' 
                              + '" '
                              + ' class="' + _menuAttribute(p_menu[i]["mLevel"],'class') + '" ' 
                              + makeOnClick(i)
                              + makeOnMouseOver(i)
                              + '>' 
                              + makeLine(i) 
                              + '</div>');
  }	
 }
 function _showMenu(firstidx,lastidx,level,start,idx) {
  var pos = p_menuAttr[1]["top"];
  var distance = 0;
  var skiplevel = "";
  if (! arguments.length) firstidx = lastidx = start = 0;
  if (level && p_menu[idx]["mUrl"].length) _processUrl(idx); 
  if (start && p_menu[start]["mVisible"]) {
  	skiplevel = p_menu[start]["mLevel"]; 
  	p_menu[start]["mVisible"] = false; 
  }
  for (var i=0;i<p_index;i++) {
   p_menu[i]["mID"] = 	document.getElementById(p_menu[i]["mName"] + i);
   p_menu[i]["mID"].style.visibility = 'hidden';
   if (skiplevel == p_menu[i]["mLevel"]) {
   	if (i == start && p_menu[i]["mLevel"] > 2) document.images["xPMimg" + (start-1)].src = p_menuAttr[1]["menu_sub"]
   	continue;
   }
   if ( (i>=firstidx && i<=lastidx && p_menu[i]["mLevel"] <= level) || (p_menu[i]["mLevel"] == 1) ) {
    if (start && i == (start -1) && p_menu[start-1]["mLevel"] > 1 && p_menu[start-1]["mSubLevel"]) document.images["xPMimg" + (start-1)].src = p_menuAttr[1]["menu_sub_open"];
    else if (level && p_menu[i]["mLevel"] >= level && p_menu[i]["mSubLevel"]) document.images["xPMimg" + i].src = p_menuAttr[1]["menu_sub"];
    (p_menu[i]["mLevel"] > 1 && p_menuAttr[1]["border"] != "") ? distance = 2 : distance = 0;
    p_menu[i]["mID"].style.top = (distance + pos) + 'px';
    p_menu[i]["mID"].style.left = p_menuAttr[p_menu[i]["mLevel"]]["left"] + 'px';
    p_menu[i]["mID"].style.visibility = 'visible';
    p_menu[i]["mVisible"] = true;
    pos += p_menuAttr[p_menu[i]["mLevel"]]["height"];
   }
   else {
    p_menu[i]["mID"].style.top = 0;
    p_menu[i]["mID"].style.left = 0;
    p_menu[i]["mID"].style.visibility = 'hidden';
    p_menu[i]["mVisible"] = false;
   }
  } 	
 }
 function _menuAttribute(mLevel,mAttr,aValue) {
  if (typeof(aValue) != 'undefined') p_menuAttr[mLevel][mAttr] = aValue;
  return p_menuAttr[mLevel][mAttr];	
 }
 function _processUrl(idx) {
  if (p_menu[idx]["mTarget"] == "" || ! xDT.window.find(p_menu[idx]["mTarget"]) ) {
    p_menu[idx]["mTarget"] = xDT.addWindow(p_menu[idx]["mTarget"],p_menu[idx]["mTitle"]); // in case no target (window) name is specified
    xDT.url(p_menu[idx]["mTarget"],p_menu[idx]["mUrl"]);
  }
  xDT.taskbar(p_menu[idx]["mTarget"]);
 }

 /*****************************/
 /* private functions *********/
 /*****************************/
 function makeLine(idx) {
  var str = '<table cellpadding="0" cellspacing="0" border="0" width="' + p_menuAttr[p_menu[idx]["mLevel"]]["width"] + '"><tr>';
  if (p_menuAttr[p_menu[idx]["mLevel"]]["offset"] != 0) str += '<td style="border:; background-color: transparent; background-image:;" nowrap="nowrap" width="' + p_menuAttr[p_menu[idx]["mLevel"]]["offset"] + '" class="' + p_menuAttr[p_menu[idx]["mLevel"]]["class"] + '"></td>';
  if (p_subitems) str += '<td style="border:; background-color: transparent; background-image:;" nowrap="nowrap" align="left" valign="middle" height="' + p_menuAttr[p_menu[idx]["mLevel"]]["height"] + '"><img name="xPMimg' + idx + '" border="0" src="' + p_menuAttr[1]["menu_sub"] + '"></td>';
  else if (p_menu[idx]["mLevel"] > 1) str += '<td style="background-color: transparent; background-image:;" nowrap="nowrap" align="left" valign="middle" height="' + p_menuAttr[p_menu[idx]["mLevel"]]["height"] + '"><img border="0" src="' + p_menuAttr[1]["menu_sub_item"] + '"></td>';
  str += '<td style="border:; background-color: transparent; background-image:;" nowrap="nowrap" align="left" valign="middle" height="' + p_menuAttr[p_menu[idx]["mLevel"]]["height"] + '"  class="' + p_menuAttr[p_menu[idx]["mLevel"]]["class"] + '">' 
         + '<a style="border:; background-color: transparent; background-image:;" href="javascript: void(0)" class="' + p_menuAttr[p_menu[idx]["mLevel"]]["class"] + '">' + p_menu[idx]["mTitle"] + '</a>'
         + '</td>';
  str += '</tr></table>';
  return str;
 }
 function makeOnClick(idx) {
  p_subitems = false; 	
  if (idx == (p_index - 1) ) return ""; // nothing to do only one menu item left
  if (p_menu[idx+1]["mLevel"] > p_menu[idx]["mLevel"]) {
   var firstidx = 0;
   var lastidx = 0;
   for (var j=idx;j>=0;j--) {if (p_menu[j]["mLevel"] == 1) {firstidx = j; break } }	// now we have first index menu
   for (var j=idx+1;j<p_index;j++) {if (p_menu[j]["mLevel"] == p_menu[idx+1]["mLevel"] || p_menu[j]["mLevel"] > 1) lastidx = j; else break;} // now we have last index menu entry
   if (p_menu[idx]["mLevel"] > 1) {p_subitems = true; p_menu[idx]["mSubLevel"] = true } else p_menu[idx]["mSubLevel"] = false;
   return ' onclick="xPM.showMenu(' + firstidx + ',' + lastidx + ',' + p_menu[idx+1]["mLevel"] + ',' + (idx+1) + ',' + idx + ')" ';
  }
  else if (p_menu[idx]["mUrl"].length) return ' onclick="xPM.processUrl(' + idx + ')" ';
  return ""; 	
 }
 function makeOnMouseOver(idx) {
  return " onmouseout=\"this.className='" +  p_menuAttr[p_menu[idx]["mLevel"]]["class"] + "'\" onmouseover=\"this.className='" +  p_menuAttr[p_menu[idx]["mLevel"]]["class"] + "_om" + "'\" ";  	
 }
 function preloadImages() {
  for (var i=0;i<arguments.length;i++) {
   var img = new Image();
   img.src = arguments[i];
  }	
 }	
}
